home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-02-24 | 3.0 KB | 155 lines | [TEXT/ROSA] |
- ;
- ; File: asm-funcs.lisp
- ;
- ; Contents: Sample lisp functions written in assembler.
- ; These routines may mimic functions used in Common
- ; Lisp, but they are not the actual functions used
- ; by the system. They are provided here as examples
- ; of how to build such functions.
- ;
- ; These routines are probably faster, and could in
- ; some cases be used to redefine the system routines
- ; for improved speed. In general, however, they
- ; don't do much argument or type checking, which the
- ; normal routines do.
- ;
-
- (in-package :user)
- (require :assembler)
-
- (defasm node-type (x)
- "(NODE-TYPE object)
- Returns the type field from a Lisp object. This is not really equivalent
- to the Lisp type, since the Lisp type contains logical distinctions
- and relationships. This is, however, the physical field used to store
- some of the type information used by the system."
- #{
- ($FUNC-BEGIN 0)
- (move.l (a0) a1)
- ($NODE-TYPE a1 d0)
- (move.l d0 (-a7))
- (jsr #'common-lisp::%integerAtom)
- (lea (a7 4) a7)
- ($RETURN d0)
- })
-
- (defasm consp_ (x)
- "Usage: (CONSP object)
- Returns T if the object is a cons cell, NIL otherwise."
- #{
- ($FUNC-BEGIN 0)
- (move.l (a0) a1)
- ($IFELSE
- ($CONSP a1)
- ((move.l 't d0))
- ((move.l 'nil d0)))
- ($RETURN d0)
- })
-
- (defasm car_ (x)
- #{
- ($FUNC-BEGIN 0)
- (move.l (a0) a0)
- ($CAR a0)
- ($RETURN a0)
- })
-
- (defasm cdr_ (x)
- #{
- ($FUNC-BEGIN 0)
- (move.l (a0) a0)
- ($CDR a0)
- ($RETURN a0)
- })
-
- (defasm rplaca_ (x y)
- #{
- ($FUNC-BEGIN 0)
- (move.l (a0) a1)
- ($SETCAR a1 (a0 4))
- ($RETURN a1)
- })
-
- (defasm rplacd_ (x y)
- #{
- ($FUNC-BEGIN 0)
- (move.l (a0) a1)
- ($SETCDR a1 (a0 4))
- ($RETURN a1)
- })
-
- ;
- ; This is an example of calling a Lisp function from assembler.
- ; In this case 'cons' is called.
- ;
- (defasm cons_ (a b)
- #{
- ($FUNC-BEGIN 0)
- (move.l 0 (-a7)) ; push NULL terminator
- (move.l (a0 4) (-a7)) ; push second arg
- (move.l (a0) (-a7)) ; push first arg
- (move.l a7 (-a7)) ; push address of block
- (jsr #'cons) ; call the function
- ($RETURN d0)
- })
-
- (defasm hundred ()
- "The 'hundred' function always returns 100."
- #{
- ($FUNC-BEGIN 0)
- (move.l 100 (-a7))
- (jsr #'common-lisp::%integerAtom)
- ($RETURN d0)
- })
-
- ;;
- ;; Examples of calling toolbox routines via traps.
- ;;
-
- ;;
- ;; Define these traps in the compiler package
- ;; They should be moved into the assembler module.
- ;;
- (in-package :assembler)
- (defconstant _SysBeep #xA9C8)
- (defconstant _Debugger #xA9FF)
- (in-package :user)
-
- (defasm sysbeep ()
- "Usage: (SYSBEEP time) -- where time is an integer.
- Causes a system beep."
- #{
- ($FUNC-BEGIN 0)
- (move.l (a0) a1)
- ($INTEGER a1 (-a7))
- (dc.w _SysBeep) ;; this trap cleans up the stack itself
- ($RETURN 'nil) ;; return nil
- })
-
-
- (defasm debugger ()
- "Usage: (DEBUGGER)
- Drops you into the mac debugger (MacsBug, for example)."
- #{
- ($FUNC-BEGIN 0)
- (dc.w _Debugger)
- ($RETURN 'nil)
- })
-
- (defasm i+ (x y)
- #{
- ($FUNC-BEGIN 0)
- (move.l (a0 4) a1)
- ($INTEGER a1 d0)
- (move.l (a0) a1)
- ($INTEGER a1 a1)
- (add.l a1 d0)
- (move.l d0 (-a7))
- (jsr #'common-lisp::%integerAtom)
- ($RETURN d0)
- })
-
- ;; note that ( add.l d1 d0 ) is broken!!!
-
-
-